vim9script noclear

var id: number = -1

export def Pin(range: number, line1: number, line2: number, pin: bool)
	if id != -1
		popup_close(id)
		id = -1
	endif

	if pin && range != 0
		var h = line2 + 1 - line1
		id = popup_create(bufnr(), {
			line: 1,
			col: &columns,
			minheight: h,
			maxheight: h,
			pos: "topright",
			tabpage: -1,
			scrollbar: 0,
		})
		win_execute(id, $"normal! {line1}G|zt")
	endif
enddef
